package com.example.configDataSource;

import com.alibaba.druid.pool.DruidDataSource;
import com.example.constant.DataSourceConst;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * Step1:提供读写分离的数据源
 * nextStep:{@link }
 */
@Configuration
public class DruidDataSourceConfig {
  /**
   * DataSource 配置
   * @return
   */
  @ConfigurationProperties(prefix = "spring.datasource.druid.read")
  @Bean(name = DataSourceConst.READ_DATASOURCE_KEY)
  public DataSource readDruidDataSource() {
    return new DruidDataSource();
  }
  /**
   * DataSource 配置
   * @return
   */
  @ConfigurationProperties(prefix = "spring.datasource.druid.write")
  @Bean(name = DataSourceConst.WRITE_DATASOURCE_KEY)
  @Primary
  public DataSource writeDruidDataSource() {
    return new DruidDataSource();
  }
}